<template>
	<view class="container">
		<view class="header-box" :style="{ height: winInfo.height + 'px', paddingTop: winInfo.top + 'px' }">
			<view class="header-info">
				<tui-icon name="arrowleft" size="25" color="#333" @tap="goBack" bold="true"></tui-icon>
				<view class="header-name">优势亮点</view>
			</view>
		</view>
		<view class="input-box">
			<textarea name="" style="width: 100%" v-model="RongyuZS" placeholder="荣誉证书" maxlength="500" id="" cols="30" rows="10"></textarea>
			<view class="count-length">{{ RongyuZS.length }}/500</view>
		</view>
		<view class="submit-button" @tap="submitInfo">保存</view>
	</view>
	
</template>

<script>
export default {
	data() {
		return {
			Islogin: this.Microi.IsLogin(),
			CurrentUser: this.Microi.GetCurrentUser(),
			winInfo: {
				height: 64, //header高度
				top: 26, //标题图标距离顶部距离
				scrollH: 0 //滚动总高度
			},
			startTime: 0,
			options: {},
			RongyuZS: ''
		};
	},
	mounted() {
		this.RongyuZS = this.CurrentUser.RongyuZS;
		let obj = {};
		// #ifdef MP-WEIXIN
		obj = wx.getMenuButtonBoundingClientRect();
		// #endif
		// #ifdef MP-BAIDU
		obj = swan.getMenuButtonBoundingClientRect();
		// #endif
		// #ifdef MP-ALIPAY
		my.hideAddToDesktopMenu();
		// #endif

		setTimeout(() => {
			uni.getSystemInfo({
				success: (res) => {
					this.winInfo = res;
					this.winInfo.width = obj.left || res.windowWidth;
					this.winInfo.height = obj.top ? obj.top + obj.height + 8 : res.statusBarHeight + 44;
					this.winInfo.top = obj.top ? obj.top + (obj.height - 32) / 2 : res.statusBarHeight + 6;
					this.winInfo.scrollH = res.windowWidth;
				}
			});
		}, 0);
	},

	onLoad(options) {
		this.options = options;
	},
	onShow() {
		this.startTime = new Date();
	},
	onHide() {
		if (this.Islogin) {
			// 获取当前页面栈
			const pages = getCurrentPages();
			// 获取当前页面的对象
			const currentPage = pages[pages.length - 1];
			// 获取当前页面的路径
			const route = currentPage.route;
			// 获取当前页面的参数
			const options = currentPage.options;
			this.Microi.ApiEngine.Run('Add_liulanLog', {
				YemianCS: options,
				YemianDZ: route,
				LiulanSJC: new Date().getTime() - this.startTime.getTime()
			});
		}
	},
	onUnload() {
		if (this.Islogin) {
			// 获取当前页面栈
			const pages = getCurrentPages();
			// 获取当前页面的对象
			const currentPage = pages[pages.length - 1];
			// 获取当前页面的路径
			const route = currentPage.route;
			// 获取当前页面的参数
			const options = currentPage.options;
			this.Microi.ApiEngine.Run('Add_liulanLog', {
				YemianCS: options,
				YemianDZ: route,
				LiulanSJC: new Date().getTime() - this.startTime.getTime()
			});
		}
	},
	methods: {
		async submitInfo() {
			var self = this;
			if (!this.RongyuZS) {
				this.Microi.Tips('请填写荣誉信息', false);
				return;
			}
			var res = await this.Microi.FormEngine.UptFormData({
				FormEngineKey: 'sys_user',
				Id: this.CurrentUser.Id,
				_RowModel: {
					RongyuZS: this.RongyuZS
				}
			});
			if (res.Code == 1) {
				this.Microi.Tips('更新成功', true);
				this.CurrentUser.RongyuZS = this.RongyuZS;
				this.Microi.SetCurrentUser(this.CurrentUser);
				setTimeout(function () {
					uni.reLaunch({
						url: '/pages/tabbar/my/my'
					});
				}, 1000);
			}
		},
		goBack() {
			let pages = getCurrentPages(); // 获取当前页面堆栈
			let pageCount = pages.length; // 页面堆栈中的页面数量
			// 判断是否有上级页面
			if (pageCount > 1) {
				// 如果有上级页面，则返回上级页面
				uni.navigateBack({
					delta: 1
				});
			} else {
				// 如果没有上级页面，则返回首页
				uni.switchTab({
					url: '/pages/tabbar/find/find' // 替换为你的首页路径
				});
			}
		}
	}
};
</script>

<style>
	page{
		background-color: #fff;
	}
.container {
	background-color: #fff;
	padding: 175rpx 20rpx 150rpx 20rpx;
	color: #000;
	box-sizing: border-box;
}

.header-box {
	width: 100%;
	position: fixed;
	left: 0;
	top: 0;
	z-index: 999;
	background-color: #fff;
	display: flex;
	align-items: center;
	justify-content: space-between;
	box-sizing: border-box;
}
.header-name {
	font-family: PingFang SC, PingFang SC;
	font-weight: 800;
	font-size: 36rpx;
	color: #181818;
	text-align: center;
	font-style: normal;
	text-transform: none;
}
.header-info {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	gap: 20rpx;
}
.header-info image {
	width: 25rpx;
}
.input-box {
	width: 100%;
	background-color: #f2f2f2;
	padding: 16rpx;
	position: relative;
	box-sizing: border-box;
	border-radius: 30rpx;
}
.count-length {
	position: absolute;
	bottom: 2%;
	right: 2%;
	font-size: 25rpx;
	color: #999;
}
.submit-button {
	width: 496rpx;
	height: 68rpx;
	background: #FB353B;
	border-radius: 80rpx 80rpx 80rpx 80rpx;
	margin: auto;
	margin-top: 100rpx;

	font-family: PingFang SC, PingFang SC;

	font-size: 32rpx;
	color: #ffffff;
	line-height: 68rpx;
	text-align: center;
	font-style: normal;
	text-transform: none;
}
</style>
